package com.china.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.china.osourcechina.R;
import com.china.vo.Blog;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/5/13.
 */
public class BoKeAdapter extends BaseAdapter{
    Context context;
    List<Blog> list;
    public BoKeAdapter(Context context,List<Blog> list) {
        this.context = context ;
        this.list = list ;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh= null;
        if (convertView == null){
            vh = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_list_item,null);
            vh.image =(ImageView)convertView.findViewById(R.id.image);
            vh.title = (TextView)convertView.findViewById(R.id.title);
            vh.body =(TextView)convertView.findViewById(R.id.body);
            vh.pubdate =(TextView)convertView.findViewById(R.id.pubdate);
            convertView.setTag(vh);
        }else {
            vh = (ViewHolder)convertView.getTag();
        }
        if (list.get(position).getUrl()!=null){
            ImageLoader.getInstance().displayImage(list.get(position).getUrl(),vh.image);
//        vh.image.setImageResource(R.mipmap.widget_today_icon);
        }
        vh.title.setText(list.get(position).getTitle());
        vh.body.setText(list.get(position).getBody());
        vh.pubdate.setText(list.get(position).getPubDate());

        return convertView;
    }
    class ViewHolder{
        ImageView image;
        TextView title;
        TextView body;
        TextView pubdate;
    }
}
